{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-06-17T01:59:11.682840Z",
     "start_time": "2025-06-17T01:59:11.663817Z"
    }
   },
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib as plt\n",
    "import seaborn as sns\n",
    "import warnings\n",
    "warnings.filterwarnings(\"ignore\")"
   ],
   "outputs": [],
   "execution_count": 2
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-17T02:12:02.783434Z",
     "start_time": "2025-06-17T02:11:50.326092Z"
    }
   },
   "cell_type": "code",
   "source": [
    "train_fail=pd.read_table(\"E:/练习/广告点击概率预测/第一轮/数据集/round1_iflyad_train.txt\")\n",
    "train_fail"
   ],
   "id": "c47d1041b9eee75f",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "                 instance_id        time             city         province  \\\n",
       "0          86294719979897807  2190219034  137103102105100  137103102100100   \n",
       "1        2699289844928136052  2190221070  137105101100100  137105101100100   \n",
       "2        3117527168445845752  2190219793  137103104111100  137103104100100   \n",
       "3        3398484891050993371  2190221704  137103102113100  137103102100100   \n",
       "4        2035477570591176488  2190220024  137103102109100  137103102100100   \n",
       "...                      ...         ...              ...              ...   \n",
       "1001645  2569120806007737669  2190058023  137104102101100  137104102100100   \n",
       "1001646  5328420823695634765  2190056965  137101103106100  137101103100100   \n",
       "1001647  2732525116033744741  2190059227  137105103108100  137105103100100   \n",
       "1001648  4026815797356128987  2190057688  137103102109100  137103102100100   \n",
       "1001649  2863771093216612552  2190058546  137104106109100  137104106100100   \n",
       "\n",
       "                                                 user_tags  carrier  devtype  \\\n",
       "0                                                      NaN        1        2   \n",
       "1        2100191,2100078,3001825,,3001781,3001791,30017...        3        2   \n",
       "2                                                      NaN        3        2   \n",
       "3        2100098,gd_2100000,3001791,3001795,3002193,300...        0        2   \n",
       "4                                                      NaN        1        2   \n",
       "...                                                    ...      ...      ...   \n",
       "1001645                                                NaN        3        2   \n",
       "1001646  3003123,3003123,3003313,3003321,3003323,300337...        1        2   \n",
       "1001647                                                NaN        1        2   \n",
       "1001648    3004406,3004450,3004430,3004434,3004448,3004500        1        2   \n",
       "1001649                                                NaN        1        2   \n",
       "\n",
       "               make            model  nnt  ...  creative_width  \\\n",
       "0            HUAWEI  HUAWEI-CAZ-AL10    1  ...            1280   \n",
       "1            Xiaomi     Redmi Note 4    1  ...             960   \n",
       "2              OPPO        OPPO+R11s    1  ...             960   \n",
       "3               NaN         OPPO A57    1  ...            1280   \n",
       "4             Apple         iPhone 7    3  ...             960   \n",
       "...             ...              ...  ...  ...             ...   \n",
       "1001645      HUAWEI         BLN-AL40    1  ...             960   \n",
       "1001646  vivo X9s L       vivo X9s L    4  ...             960   \n",
       "1001647        vivo         vivo Y79    1  ...             960   \n",
       "1001648      HUAWEI         EML-AL00    4  ...             960   \n",
       "1001649      HUAWEI         KIW-UL00    1  ...             960   \n",
       "\n",
       "        creative_height creative_is_jump  creative_is_download  \\\n",
       "0                   720             True                 False   \n",
       "1                   640             True                 False   \n",
       "2                   640             True                 False   \n",
       "3                   720             True                 False   \n",
       "4                   640             True                 False   \n",
       "...                 ...              ...                   ...   \n",
       "1001645             640             True                 False   \n",
       "1001646             640             True                 False   \n",
       "1001647             640             True                 False   \n",
       "1001648             640             True                 False   \n",
       "1001649             640             True                 False   \n",
       "\n",
       "         creative_is_js  creative_is_voicead creative_has_deeplink  app_paid  \\\n",
       "0                 False                False                 False     False   \n",
       "1                 False                False                 False     False   \n",
       "2                 False                False                 False     False   \n",
       "3                 False                False                 False     False   \n",
       "4                 False                False                 False     False   \n",
       "...                 ...                  ...                   ...       ...   \n",
       "1001645           False                False                 False     False   \n",
       "1001646           False                False                 False     False   \n",
       "1001647           False                False                 False     False   \n",
       "1001648           False                False                 False     False   \n",
       "1001649           False                False                 False     False   \n",
       "\n",
       "              advert_name  click  \n",
       "0        B4734117F35EE97F      0  \n",
       "1        B4734117F35EE97F      0  \n",
       "2        E257895F74792E81      0  \n",
       "3        0A421D7B11EABFC5      0  \n",
       "4        B4734117F35EE97F      0  \n",
       "...                   ...    ...  \n",
       "1001645  E257895F74792E81      0  \n",
       "1001646  B4734117F35EE97F      1  \n",
       "1001647  B4734117F35EE97F      0  \n",
       "1001648  B4734117F35EE97F      1  \n",
       "1001649  E257895F74792E81      1  \n",
       "\n",
       "[1001650 rows x 35 columns]"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>instance_id</th>\n",
       "      <th>time</th>\n",
       "      <th>city</th>\n",
       "      <th>province</th>\n",
       "      <th>user_tags</th>\n",
       "      <th>carrier</th>\n",
       "      <th>devtype</th>\n",
       "      <th>make</th>\n",
       "      <th>model</th>\n",
       "      <th>nnt</th>\n",
       "      <th>...</th>\n",
       "      <th>creative_width</th>\n",
       "      <th>creative_height</th>\n",
       "      <th>creative_is_jump</th>\n",
       "      <th>creative_is_download</th>\n",
       "      <th>creative_is_js</th>\n",
       "      <th>creative_is_voicead</th>\n",
       "      <th>creative_has_deeplink</th>\n",
       "      <th>app_paid</th>\n",
       "      <th>advert_name</th>\n",
       "      <th>click</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>86294719979897807</td>\n",
       "      <td>2190219034</td>\n",
       "      <td>137103102105100</td>\n",
       "      <td>137103102100100</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>HUAWEI</td>\n",
       "      <td>HUAWEI-CAZ-AL10</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>1280</td>\n",
       "      <td>720</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>B4734117F35EE97F</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2699289844928136052</td>\n",
       "      <td>2190221070</td>\n",
       "      <td>137105101100100</td>\n",
       "      <td>137105101100100</td>\n",
       "      <td>2100191,2100078,3001825,,3001781,3001791,30017...</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>Xiaomi</td>\n",
       "      <td>Redmi Note 4</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>960</td>\n",
       "      <td>640</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>B4734117F35EE97F</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3117527168445845752</td>\n",
       "      <td>2190219793</td>\n",
       "      <td>137103104111100</td>\n",
       "      <td>137103104100100</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>OPPO</td>\n",
       "      <td>OPPO+R11s</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>960</td>\n",
       "      <td>640</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>E257895F74792E81</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3398484891050993371</td>\n",
       "      <td>2190221704</td>\n",
       "      <td>137103102113100</td>\n",
       "      <td>137103102100100</td>\n",
       "      <td>2100098,gd_2100000,3001791,3001795,3002193,300...</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>OPPO A57</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>1280</td>\n",
       "      <td>720</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>0A421D7B11EABFC5</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2035477570591176488</td>\n",
       "      <td>2190220024</td>\n",
       "      <td>137103102109100</td>\n",
       "      <td>137103102100100</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>Apple</td>\n",
       "      <td>iPhone 7</td>\n",
       "      <td>3</td>\n",
       "      <td>...</td>\n",
       "      <td>960</td>\n",
       "      <td>640</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>B4734117F35EE97F</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1001645</th>\n",
       "      <td>2569120806007737669</td>\n",
       "      <td>2190058023</td>\n",
       "      <td>137104102101100</td>\n",
       "      <td>137104102100100</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>HUAWEI</td>\n",
       "      <td>BLN-AL40</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>960</td>\n",
       "      <td>640</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>E257895F74792E81</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1001646</th>\n",
       "      <td>5328420823695634765</td>\n",
       "      <td>2190056965</td>\n",
       "      <td>137101103106100</td>\n",
       "      <td>137101103100100</td>\n",
       "      <td>3003123,3003123,3003313,3003321,3003323,300337...</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>vivo X9s L</td>\n",
       "      <td>vivo X9s L</td>\n",
       "      <td>4</td>\n",
       "      <td>...</td>\n",
       "      <td>960</td>\n",
       "      <td>640</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>B4734117F35EE97F</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1001647</th>\n",
       "      <td>2732525116033744741</td>\n",
       "      <td>2190059227</td>\n",
       "      <td>137105103108100</td>\n",
       "      <td>137105103100100</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>vivo</td>\n",
       "      <td>vivo Y79</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>960</td>\n",
       "      <td>640</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>B4734117F35EE97F</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1001648</th>\n",
       "      <td>4026815797356128987</td>\n",
       "      <td>2190057688</td>\n",
       "      <td>137103102109100</td>\n",
       "      <td>137103102100100</td>\n",
       "      <td>3004406,3004450,3004430,3004434,3004448,3004500</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>HUAWEI</td>\n",
       "      <td>EML-AL00</td>\n",
       "      <td>4</td>\n",
       "      <td>...</td>\n",
       "      <td>960</td>\n",
       "      <td>640</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>B4734117F35EE97F</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1001649</th>\n",
       "      <td>2863771093216612552</td>\n",
       "      <td>2190058546</td>\n",
       "      <td>137104106109100</td>\n",
       "      <td>137104106100100</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>HUAWEI</td>\n",
       "      <td>KIW-UL00</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>960</td>\n",
       "      <td>640</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>E257895F74792E81</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1001650 rows × 35 columns</p>\n",
       "</div>"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 8
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-17T02:12:16.593988Z",
     "start_time": "2025-06-17T02:12:15.841500Z"
    }
   },
   "cell_type": "code",
   "source": "train_fail.info()",
   "id": "784b4d1f219dca94",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 1001650 entries, 0 to 1001649\n",
      "Data columns (total 35 columns):\n",
      " #   Column                 Non-Null Count    Dtype  \n",
      "---  ------                 --------------    -----  \n",
      " 0   instance_id            1001650 non-null  int64  \n",
      " 1   time                   1001650 non-null  int64  \n",
      " 2   city                   1001650 non-null  int64  \n",
      " 3   province               1001650 non-null  int64  \n",
      " 4   user_tags              691880 non-null   object \n",
      " 5   carrier                1001650 non-null  int64  \n",
      " 6   devtype                1001650 non-null  int64  \n",
      " 7   make                   902733 non-null   object \n",
      " 8   model                  994248 non-null   object \n",
      " 9   nnt                    1001650 non-null  int64  \n",
      " 10  os                     1001650 non-null  int64  \n",
      " 11  osv                    993878 non-null   object \n",
      " 12  os_name                1001650 non-null  object \n",
      " 13  adid                   1001650 non-null  int64  \n",
      " 14  advert_id              1001650 non-null  int64  \n",
      " 15  orderid                1001650 non-null  int64  \n",
      " 16  advert_industry_inner  1001650 non-null  object \n",
      " 17  campaign_id            1001650 non-null  int64  \n",
      " 18  creative_id            1001650 non-null  int64  \n",
      " 19  creative_tp_dnf        1001650 non-null  int64  \n",
      " 20  app_cate_id            999383 non-null   float64\n",
      " 21  f_channel              76390 non-null    object \n",
      " 22  app_id                 999383 non-null   float64\n",
      " 23  inner_slot_id          1001650 non-null  object \n",
      " 24  creative_type          1001650 non-null  int64  \n",
      " 25  creative_width         1001650 non-null  int64  \n",
      " 26  creative_height        1001650 non-null  int64  \n",
      " 27  creative_is_jump       1001650 non-null  bool   \n",
      " 28  creative_is_download   1001650 non-null  bool   \n",
      " 29  creative_is_js         1001650 non-null  bool   \n",
      " 30  creative_is_voicead    1001650 non-null  bool   \n",
      " 31  creative_has_deeplink  1001650 non-null  bool   \n",
      " 32  app_paid               1001650 non-null  bool   \n",
      " 33  advert_name            1001650 non-null  object \n",
      " 34  click                  1001650 non-null  int64  \n",
      "dtypes: bool(6), float64(2), int64(18), object(9)\n",
      "memory usage: 227.3+ MB\n"
     ]
    }
   ],
   "execution_count": 9
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-17T08:56:45.055042Z",
     "start_time": "2025-06-17T08:56:44.499125Z"
    }
   },
   "cell_type": "code",
   "source": [
    "test_fail=pd.read_table(\"E:/练习/广告点击概率预测/第一轮/数据集/round1_iflyad_test_feature.txt\")\n",
    "test_fail"
   ],
   "id": "e07d55da35ac8bf0",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "               instance_id        time             city         province  \\\n",
       "0      6930856710792380886  2190675456  137103104101100  137103104100100   \n",
       "1      5460409694420131920  2190674821  137103104112100  137103104100100   \n",
       "2       982813438159141507  2190674111  137105103101100  137105103100100   \n",
       "3       529991959116679673  2190675256  137106101107100  137106101100100   \n",
       "4      5357053206615171780  2190673926  137103102101100  137103102100100   \n",
       "...                    ...         ...              ...              ...   \n",
       "40019    40306859142640381  2190717893  137106102110100  137106102100100   \n",
       "40020  3340909964064239064  2190717210  137101103107100  137101103100100   \n",
       "40021  4795201264091979641  2190715980  137103107116100  137103107100100   \n",
       "40022  7249824726452760884  2190716114  137103106111100  137103106100100   \n",
       "40023  6324759195855019847  2190715765  137104101114100  137104101100100   \n",
       "\n",
       "                                               user_tags  carrier  devtype  \\\n",
       "0                                                    NaN        2        2   \n",
       "1                                3004406,3004430,3004434        1        2   \n",
       "2      3003779,3003843,3003851,3003863,3003865,300386...        2        2   \n",
       "3                                                    NaN        2        2   \n",
       "4      2100191,2100041,2100078,2100136,2100042,300182...        3        2   \n",
       "...                                                  ...      ...      ...   \n",
       "40019  2100013,2100003,2100004,gd_2100000,2100084,210...        1        2   \n",
       "40020  ,3003315,3003321,3003323,3003537,3004081,30044...        1        2   \n",
       "40021      3003123,gd_2100001,ag_2100038,3004430,3004434        1        2   \n",
       "40022  ,3003525,3003563,3003779,3003843,3003851,30038...        1        2   \n",
       "40023  2100235,gd_2100001,2100126,3001793,3001949,300...        1        2   \n",
       "\n",
       "            make            model  nnt  ...  creative_type creative_width  \\\n",
       "0          Apple    iPhone 8 Plus    1  ...              8            960   \n",
       "1           vivo      vivo X9Plus    1  ...              8            960   \n",
       "2      OPPO A73t        OPPO A73t    4  ...              5            160   \n",
       "3        vivo Z1          vivo Z1    4  ...              8            960   \n",
       "4         HUAWEI  HUAWEI MLA-AL10    4  ...              5            320   \n",
       "...          ...              ...  ...  ...            ...            ...   \n",
       "40019       OPPO         OPPO-R9s    1  ...              8            960   \n",
       "40020     Xiaomi            MI-5X    1  ...              8            960   \n",
       "40021       vivo         vivo Y37    0  ...              8            960   \n",
       "40022       vivo      vivo%20Y75A    3  ...              8            960   \n",
       "40023       OPPO              A31    1  ...              8            960   \n",
       "\n",
       "      creative_height  creative_is_jump  creative_is_download  creative_is_js  \\\n",
       "0                 640              True                 False           False   \n",
       "1                 640              True                 False           False   \n",
       "2                 640              True                 False           False   \n",
       "3                 640              True                 False           False   \n",
       "4                 480              True                 False           False   \n",
       "...               ...               ...                   ...             ...   \n",
       "40019             640              True                 False           False   \n",
       "40020             640              True                 False           False   \n",
       "40021             640              True                 False           False   \n",
       "40022             640              True                 False           False   \n",
       "40023             640              True                 False           False   \n",
       "\n",
       "      creative_is_voicead  creative_has_deeplink  app_paid       advert_name  \n",
       "0                   False                  False     False  B4734117F35EE97F  \n",
       "1                   False                  False     False  B4734117F35EE97F  \n",
       "2                   False                  False     False  B4734117F35EE97F  \n",
       "3                   False                  False     False  B4734117F35EE97F  \n",
       "4                   False                  False     False  42A4CB9035B7F50E  \n",
       "...                   ...                    ...       ...               ...  \n",
       "40019               False                  False     False  B4734117F35EE97F  \n",
       "40020               False                  False     False  D54E631F07CA4751  \n",
       "40021               False                  False     False  50822F8310CAE01D  \n",
       "40022               False                  False     False  B4734117F35EE97F  \n",
       "40023               False                  False     False  D54E631F07CA4751  \n",
       "\n",
       "[40024 rows x 34 columns]"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>instance_id</th>\n",
       "      <th>time</th>\n",
       "      <th>city</th>\n",
       "      <th>province</th>\n",
       "      <th>user_tags</th>\n",
       "      <th>carrier</th>\n",
       "      <th>devtype</th>\n",
       "      <th>make</th>\n",
       "      <th>model</th>\n",
       "      <th>nnt</th>\n",
       "      <th>...</th>\n",
       "      <th>creative_type</th>\n",
       "      <th>creative_width</th>\n",
       "      <th>creative_height</th>\n",
       "      <th>creative_is_jump</th>\n",
       "      <th>creative_is_download</th>\n",
       "      <th>creative_is_js</th>\n",
       "      <th>creative_is_voicead</th>\n",
       "      <th>creative_has_deeplink</th>\n",
       "      <th>app_paid</th>\n",
       "      <th>advert_name</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>6930856710792380886</td>\n",
       "      <td>2190675456</td>\n",
       "      <td>137103104101100</td>\n",
       "      <td>137103104100100</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>Apple</td>\n",
       "      <td>iPhone 8 Plus</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>8</td>\n",
       "      <td>960</td>\n",
       "      <td>640</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>B4734117F35EE97F</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>5460409694420131920</td>\n",
       "      <td>2190674821</td>\n",
       "      <td>137103104112100</td>\n",
       "      <td>137103104100100</td>\n",
       "      <td>3004406,3004430,3004434</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>vivo</td>\n",
       "      <td>vivo X9Plus</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>8</td>\n",
       "      <td>960</td>\n",
       "      <td>640</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>B4734117F35EE97F</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>982813438159141507</td>\n",
       "      <td>2190674111</td>\n",
       "      <td>137105103101100</td>\n",
       "      <td>137105103100100</td>\n",
       "      <td>3003779,3003843,3003851,3003863,3003865,300386...</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>OPPO A73t</td>\n",
       "      <td>OPPO A73t</td>\n",
       "      <td>4</td>\n",
       "      <td>...</td>\n",
       "      <td>5</td>\n",
       "      <td>160</td>\n",
       "      <td>640</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>B4734117F35EE97F</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>529991959116679673</td>\n",
       "      <td>2190675256</td>\n",
       "      <td>137106101107100</td>\n",
       "      <td>137106101100100</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>vivo Z1</td>\n",
       "      <td>vivo Z1</td>\n",
       "      <td>4</td>\n",
       "      <td>...</td>\n",
       "      <td>8</td>\n",
       "      <td>960</td>\n",
       "      <td>640</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>B4734117F35EE97F</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5357053206615171780</td>\n",
       "      <td>2190673926</td>\n",
       "      <td>137103102101100</td>\n",
       "      <td>137103102100100</td>\n",
       "      <td>2100191,2100041,2100078,2100136,2100042,300182...</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>HUAWEI</td>\n",
       "      <td>HUAWEI MLA-AL10</td>\n",
       "      <td>4</td>\n",
       "      <td>...</td>\n",
       "      <td>5</td>\n",
       "      <td>320</td>\n",
       "      <td>480</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>42A4CB9035B7F50E</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40019</th>\n",
       "      <td>40306859142640381</td>\n",
       "      <td>2190717893</td>\n",
       "      <td>137106102110100</td>\n",
       "      <td>137106102100100</td>\n",
       "      <td>2100013,2100003,2100004,gd_2100000,2100084,210...</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>OPPO</td>\n",
       "      <td>OPPO-R9s</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>8</td>\n",
       "      <td>960</td>\n",
       "      <td>640</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>B4734117F35EE97F</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40020</th>\n",
       "      <td>3340909964064239064</td>\n",
       "      <td>2190717210</td>\n",
       "      <td>137101103107100</td>\n",
       "      <td>137101103100100</td>\n",
       "      <td>,3003315,3003321,3003323,3003537,3004081,30044...</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>Xiaomi</td>\n",
       "      <td>MI-5X</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>8</td>\n",
       "      <td>960</td>\n",
       "      <td>640</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>D54E631F07CA4751</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40021</th>\n",
       "      <td>4795201264091979641</td>\n",
       "      <td>2190715980</td>\n",
       "      <td>137103107116100</td>\n",
       "      <td>137103107100100</td>\n",
       "      <td>3003123,gd_2100001,ag_2100038,3004430,3004434</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>vivo</td>\n",
       "      <td>vivo Y37</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>8</td>\n",
       "      <td>960</td>\n",
       "      <td>640</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>50822F8310CAE01D</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40022</th>\n",
       "      <td>7249824726452760884</td>\n",
       "      <td>2190716114</td>\n",
       "      <td>137103106111100</td>\n",
       "      <td>137103106100100</td>\n",
       "      <td>,3003525,3003563,3003779,3003843,3003851,30038...</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>vivo</td>\n",
       "      <td>vivo%20Y75A</td>\n",
       "      <td>3</td>\n",
       "      <td>...</td>\n",
       "      <td>8</td>\n",
       "      <td>960</td>\n",
       "      <td>640</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>B4734117F35EE97F</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40023</th>\n",
       "      <td>6324759195855019847</td>\n",
       "      <td>2190715765</td>\n",
       "      <td>137104101114100</td>\n",
       "      <td>137104101100100</td>\n",
       "      <td>2100235,gd_2100001,2100126,3001793,3001949,300...</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>OPPO</td>\n",
       "      <td>A31</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>8</td>\n",
       "      <td>960</td>\n",
       "      <td>640</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>D54E631F07CA4751</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>40024 rows × 34 columns</p>\n",
       "</div>"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 30
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-17T02:11:32.918937Z",
     "start_time": "2025-06-17T02:11:32.867434Z"
    }
   },
   "cell_type": "code",
   "source": "test_fail.info()",
   "id": "5ebd460ef759a658",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 40024 entries, 0 to 40023\n",
      "Data columns (total 34 columns):\n",
      " #   Column                 Non-Null Count  Dtype  \n",
      "---  ------                 --------------  -----  \n",
      " 0   instance_id            40024 non-null  int64  \n",
      " 1   time                   40024 non-null  int64  \n",
      " 2   city                   40024 non-null  int64  \n",
      " 3   province               40024 non-null  int64  \n",
      " 4   user_tags              26792 non-null  object \n",
      " 5   carrier                40024 non-null  int64  \n",
      " 6   devtype                40024 non-null  int64  \n",
      " 7   make                   35898 non-null  object \n",
      " 8   model                  39633 non-null  object \n",
      " 9   nnt                    40024 non-null  int64  \n",
      " 10  os                     40024 non-null  int64  \n",
      " 11  osv                    39585 non-null  object \n",
      " 12  os_name                40024 non-null  object \n",
      " 13  adid                   40024 non-null  int64  \n",
      " 14  advert_id              40024 non-null  int64  \n",
      " 15  orderid                40024 non-null  int64  \n",
      " 16  advert_industry_inner  40024 non-null  object \n",
      " 17  campaign_id            40024 non-null  int64  \n",
      " 18  creative_id            40024 non-null  int64  \n",
      " 19  creative_tp_dnf        40024 non-null  int64  \n",
      " 20  app_cate_id            39993 non-null  float64\n",
      " 21  f_channel              3387 non-null   object \n",
      " 22  app_id                 39993 non-null  float64\n",
      " 23  inner_slot_id          40024 non-null  object \n",
      " 24  creative_type          40024 non-null  int64  \n",
      " 25  creative_width         40024 non-null  int64  \n",
      " 26  creative_height        40024 non-null  int64  \n",
      " 27  creative_is_jump       40024 non-null  bool   \n",
      " 28  creative_is_download   40024 non-null  bool   \n",
      " 29  creative_is_js         40024 non-null  bool   \n",
      " 30  creative_is_voicead    40024 non-null  bool   \n",
      " 31  creative_has_deeplink  40024 non-null  bool   \n",
      " 32  app_paid               40024 non-null  bool   \n",
      " 33  advert_name            40024 non-null  object \n",
      "dtypes: bool(6), float64(2), int64(17), object(9)\n",
      "memory usage: 8.8+ MB\n"
     ]
    }
   ],
   "execution_count": 7
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-17T02:14:27.905040Z",
     "start_time": "2025-06-17T02:14:26.960021Z"
    }
   },
   "cell_type": "code",
   "source": [
    "data=pd.concat([train_fail,test_fail],axis=0)\n",
    "data.info();"
   ],
   "id": "ec63108bac63c35d",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Index: 1041674 entries, 0 to 40023\n",
      "Data columns (total 35 columns):\n",
      " #   Column                 Non-Null Count    Dtype  \n",
      "---  ------                 --------------    -----  \n",
      " 0   instance_id            1041674 non-null  int64  \n",
      " 1   time                   1041674 non-null  int64  \n",
      " 2   city                   1041674 non-null  int64  \n",
      " 3   province               1041674 non-null  int64  \n",
      " 4   user_tags              718672 non-null   object \n",
      " 5   carrier                1041674 non-null  int64  \n",
      " 6   devtype                1041674 non-null  int64  \n",
      " 7   make                   938631 non-null   object \n",
      " 8   model                  1033881 non-null  object \n",
      " 9   nnt                    1041674 non-null  int64  \n",
      " 10  os                     1041674 non-null  int64  \n",
      " 11  osv                    1033463 non-null  object \n",
      " 12  os_name                1041674 non-null  object \n",
      " 13  adid                   1041674 non-null  int64  \n",
      " 14  advert_id              1041674 non-null  int64  \n",
      " 15  orderid                1041674 non-null  int64  \n",
      " 16  advert_industry_inner  1041674 non-null  object \n",
      " 17  campaign_id            1041674 non-null  int64  \n",
      " 18  creative_id            1041674 non-null  int64  \n",
      " 19  creative_tp_dnf        1041674 non-null  int64  \n",
      " 20  app_cate_id            1039376 non-null  float64\n",
      " 21  f_channel              79777 non-null    object \n",
      " 22  app_id                 1039376 non-null  float64\n",
      " 23  inner_slot_id          1041674 non-null  object \n",
      " 24  creative_type          1041674 non-null  int64  \n",
      " 25  creative_width         1041674 non-null  int64  \n",
      " 26  creative_height        1041674 non-null  int64  \n",
      " 27  creative_is_jump       1041674 non-null  bool   \n",
      " 28  creative_is_download   1041674 non-null  bool   \n",
      " 29  creative_is_js         1041674 non-null  bool   \n",
      " 30  creative_is_voicead    1041674 non-null  bool   \n",
      " 31  creative_has_deeplink  1041674 non-null  bool   \n",
      " 32  app_paid               1041674 non-null  bool   \n",
      " 33  advert_name            1041674 non-null  object \n",
      " 34  click                  1001650 non-null  float64\n",
      "dtypes: bool(6), float64(3), int64(17), object(9)\n",
      "memory usage: 244.4+ MB\n"
     ]
    }
   ],
   "execution_count": 10
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-17T02:18:24.508973Z",
     "start_time": "2025-06-17T02:18:22.650753Z"
    }
   },
   "cell_type": "code",
   "source": [
    "data['user_tags'] = data['user_tags'].fillna(str(-1))\n",
    "data['make'] = data['make'].fillna(str(-1))\n",
    "data['model'] = data['model'].fillna(str(-1))\n",
    "data['osv'] = data['osv'].fillna(str(-1))\n",
    "data['app_cate_id'] = data['app_cate_id'].fillna(-1)\n",
    "data['f_channel'] = data['f_channel'].fillna(str(-1))\n",
    "data['app_id'] = data['app_id'].fillna(-1)\n",
    "data['click'] = data['click'].fillna(-1)\n",
    "data.info();"
   ],
   "id": "f51febf0ceebac69",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Index: 1041674 entries, 0 to 40023\n",
      "Data columns (total 35 columns):\n",
      " #   Column                 Non-Null Count    Dtype  \n",
      "---  ------                 --------------    -----  \n",
      " 0   instance_id            1041674 non-null  int64  \n",
      " 1   time                   1041674 non-null  int64  \n",
      " 2   city                   1041674 non-null  int64  \n",
      " 3   province               1041674 non-null  int64  \n",
      " 4   user_tags              1041674 non-null  object \n",
      " 5   carrier                1041674 non-null  int64  \n",
      " 6   devtype                1041674 non-null  int64  \n",
      " 7   make                   1041674 non-null  object \n",
      " 8   model                  1041674 non-null  object \n",
      " 9   nnt                    1041674 non-null  int64  \n",
      " 10  os                     1041674 non-null  int64  \n",
      " 11  osv                    1041674 non-null  object \n",
      " 12  os_name                1041674 non-null  object \n",
      " 13  adid                   1041674 non-null  int64  \n",
      " 14  advert_id              1041674 non-null  int64  \n",
      " 15  orderid                1041674 non-null  int64  \n",
      " 16  advert_industry_inner  1041674 non-null  object \n",
      " 17  campaign_id            1041674 non-null  int64  \n",
      " 18  creative_id            1041674 non-null  int64  \n",
      " 19  creative_tp_dnf        1041674 non-null  int64  \n",
      " 20  app_cate_id            1041674 non-null  float64\n",
      " 21  f_channel              1041674 non-null  object \n",
      " 22  app_id                 1041674 non-null  float64\n",
      " 23  inner_slot_id          1041674 non-null  object \n",
      " 24  creative_type          1041674 non-null  int64  \n",
      " 25  creative_width         1041674 non-null  int64  \n",
      " 26  creative_height        1041674 non-null  int64  \n",
      " 27  creative_is_jump       1041674 non-null  bool   \n",
      " 28  creative_is_download   1041674 non-null  bool   \n",
      " 29  creative_is_js         1041674 non-null  bool   \n",
      " 30  creative_is_voicead    1041674 non-null  bool   \n",
      " 31  creative_has_deeplink  1041674 non-null  bool   \n",
      " 32  app_paid               1041674 non-null  bool   \n",
      " 33  advert_name            1041674 non-null  object \n",
      " 34  click                  1041674 non-null  float64\n",
      "dtypes: bool(6), float64(3), int64(17), object(9)\n",
      "memory usage: 244.4+ MB\n"
     ]
    }
   ],
   "execution_count": 11
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-17T03:14:04.685062Z",
     "start_time": "2025-06-17T03:13:54.041214Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from sklearn.preprocessing import LabelEncoder\n",
    "# replace\n",
    "replace = ['creative_is_jump', 'creative_is_download', 'creative_is_js', 'creative_is_voicead', 'creative_has_deeplink', 'app_paid']\n",
    "for feat in replace:\n",
    "    data[feat] = data[feat].replace([False, True], [0, 1])\n",
    "# labelencoder 转化\n",
    "encoder = ['city', 'province', 'make', 'model', 'osv', 'os_name', 'adid', 'advert_id', 'orderid',\n",
    "           'advert_industry_inner', 'campaign_id', 'creative_id', 'app_cate_id',\n",
    "           'app_id', 'inner_slot_id', 'advert_name', 'f_channel', 'creative_tp_dnf']\n",
    "col_encoder = LabelEncoder()\n",
    "for feat in encoder:\n",
    "    col_encoder.fit(data[feat])\n",
    "    data[feat] = col_encoder.transform(data[feat])"
   ],
   "id": "8227a071602124c9",
   "outputs": [],
   "execution_count": 13
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-17T03:14:13.640506Z",
     "start_time": "2025-06-17T03:14:12.780353Z"
    }
   },
   "cell_type": "code",
   "source": "data",
   "id": "ca1fd5a033ece913",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "               instance_id        time  city  province  \\\n",
       "0        86294719979897807  2190219034    78        10   \n",
       "1      2699289844928136052  2190221070   234        22   \n",
       "2      3117527168445845752  2190219793   108        12   \n",
       "3      3398484891050993371  2190221704    86        10   \n",
       "4      2035477570591176488  2190220024    82        10   \n",
       "...                    ...         ...   ...       ...   \n",
       "40019    40306859142640381  2190717893   300        28   \n",
       "40020  3340909964064239064  2190717210     9         3   \n",
       "40021  4795201264091979641  2190715980   150        15   \n",
       "40022  7249824726452760884  2190716114   133        14   \n",
       "40023  6324759195855019847  2190715765   165        16   \n",
       "\n",
       "                                               user_tags  carrier  devtype  \\\n",
       "0                                                     -1        1        2   \n",
       "1      2100191,2100078,3001825,,3001781,3001791,30017...        3        2   \n",
       "2                                                     -1        3        2   \n",
       "3      2100098,gd_2100000,3001791,3001795,3002193,300...        0        2   \n",
       "4                                                     -1        1        2   \n",
       "...                                                  ...      ...      ...   \n",
       "40019  2100013,2100003,2100004,gd_2100000,2100084,210...        1        2   \n",
       "40020  ,3003315,3003321,3003323,3003537,3004081,30044...        1        2   \n",
       "40021      3003123,gd_2100001,ag_2100038,3004430,3004434        1        2   \n",
       "40022  ,3003525,3003563,3003779,3003843,3003851,30038...        1        2   \n",
       "40023  2100235,gd_2100001,2100126,3001793,3001949,300...        1        2   \n",
       "\n",
       "       make  model  nnt  ...  creative_width  creative_height  \\\n",
       "0       865   3748    1  ...            1280              720   \n",
       "1      2409   7852    1  ...             960              640   \n",
       "2      1619   7128    1  ...             960              640   \n",
       "3       133   6628    1  ...            1280              720   \n",
       "4       292  10939    3  ...             960              640   \n",
       "...     ...    ...  ...  ...             ...              ...   \n",
       "40019  1619   7197    1  ...             960              640   \n",
       "40020  2409   6015    1  ...             960              640   \n",
       "40021  2898  12605    0  ...             960              640   \n",
       "40022  2898  12867    3  ...             960              640   \n",
       "40023  1619    408    1  ...             960              640   \n",
       "\n",
       "       creative_is_jump  creative_is_download  creative_is_js  \\\n",
       "0                     1                     0               0   \n",
       "1                     1                     0               0   \n",
       "2                     1                     0               0   \n",
       "3                     1                     0               0   \n",
       "4                     1                     0               0   \n",
       "...                 ...                   ...             ...   \n",
       "40019                 1                     0               0   \n",
       "40020                 1                     0               0   \n",
       "40021                 1                     0               0   \n",
       "40022                 1                     0               0   \n",
       "40023                 1                     0               0   \n",
       "\n",
       "       creative_is_voicead  creative_has_deeplink  app_paid  advert_name  \\\n",
       "0                        0                      0         0           25   \n",
       "1                        0                      0         0           25   \n",
       "2                        0                      0         0           32   \n",
       "3                        0                      0         0            0   \n",
       "4                        0                      0         0           25   \n",
       "...                    ...                    ...       ...          ...   \n",
       "40019                    0                      0         0           25   \n",
       "40020                    0                      0         0           30   \n",
       "40021                    0                      0         0           11   \n",
       "40022                    0                      0         0           25   \n",
       "40023                    0                      0         0           30   \n",
       "\n",
       "       click  \n",
       "0        0.0  \n",
       "1        0.0  \n",
       "2        0.0  \n",
       "3        0.0  \n",
       "4        0.0  \n",
       "...      ...  \n",
       "40019   -1.0  \n",
       "40020   -1.0  \n",
       "40021   -1.0  \n",
       "40022   -1.0  \n",
       "40023   -1.0  \n",
       "\n",
       "[1041674 rows x 35 columns]"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>instance_id</th>\n",
       "      <th>time</th>\n",
       "      <th>city</th>\n",
       "      <th>province</th>\n",
       "      <th>user_tags</th>\n",
       "      <th>carrier</th>\n",
       "      <th>devtype</th>\n",
       "      <th>make</th>\n",
       "      <th>model</th>\n",
       "      <th>nnt</th>\n",
       "      <th>...</th>\n",
       "      <th>creative_width</th>\n",
       "      <th>creative_height</th>\n",
       "      <th>creative_is_jump</th>\n",
       "      <th>creative_is_download</th>\n",
       "      <th>creative_is_js</th>\n",
       "      <th>creative_is_voicead</th>\n",
       "      <th>creative_has_deeplink</th>\n",
       "      <th>app_paid</th>\n",
       "      <th>advert_name</th>\n",
       "      <th>click</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>86294719979897807</td>\n",
       "      <td>2190219034</td>\n",
       "      <td>78</td>\n",
       "      <td>10</td>\n",
       "      <td>-1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>865</td>\n",
       "      <td>3748</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>1280</td>\n",
       "      <td>720</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>25</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2699289844928136052</td>\n",
       "      <td>2190221070</td>\n",
       "      <td>234</td>\n",
       "      <td>22</td>\n",
       "      <td>2100191,2100078,3001825,,3001781,3001791,30017...</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>2409</td>\n",
       "      <td>7852</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>960</td>\n",
       "      <td>640</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>25</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3117527168445845752</td>\n",
       "      <td>2190219793</td>\n",
       "      <td>108</td>\n",
       "      <td>12</td>\n",
       "      <td>-1</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>1619</td>\n",
       "      <td>7128</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>960</td>\n",
       "      <td>640</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>32</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3398484891050993371</td>\n",
       "      <td>2190221704</td>\n",
       "      <td>86</td>\n",
       "      <td>10</td>\n",
       "      <td>2100098,gd_2100000,3001791,3001795,3002193,300...</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>133</td>\n",
       "      <td>6628</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>1280</td>\n",
       "      <td>720</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2035477570591176488</td>\n",
       "      <td>2190220024</td>\n",
       "      <td>82</td>\n",
       "      <td>10</td>\n",
       "      <td>-1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>292</td>\n",
       "      <td>10939</td>\n",
       "      <td>3</td>\n",
       "      <td>...</td>\n",
       "      <td>960</td>\n",
       "      <td>640</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>25</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40019</th>\n",
       "      <td>40306859142640381</td>\n",
       "      <td>2190717893</td>\n",
       "      <td>300</td>\n",
       "      <td>28</td>\n",
       "      <td>2100013,2100003,2100004,gd_2100000,2100084,210...</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1619</td>\n",
       "      <td>7197</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>960</td>\n",
       "      <td>640</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>25</td>\n",
       "      <td>-1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40020</th>\n",
       "      <td>3340909964064239064</td>\n",
       "      <td>2190717210</td>\n",
       "      <td>9</td>\n",
       "      <td>3</td>\n",
       "      <td>,3003315,3003321,3003323,3003537,3004081,30044...</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>2409</td>\n",
       "      <td>6015</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>960</td>\n",
       "      <td>640</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>30</td>\n",
       "      <td>-1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40021</th>\n",
       "      <td>4795201264091979641</td>\n",
       "      <td>2190715980</td>\n",
       "      <td>150</td>\n",
       "      <td>15</td>\n",
       "      <td>3003123,gd_2100001,ag_2100038,3004430,3004434</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>2898</td>\n",
       "      <td>12605</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>960</td>\n",
       "      <td>640</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>11</td>\n",
       "      <td>-1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40022</th>\n",
       "      <td>7249824726452760884</td>\n",
       "      <td>2190716114</td>\n",
       "      <td>133</td>\n",
       "      <td>14</td>\n",
       "      <td>,3003525,3003563,3003779,3003843,3003851,30038...</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>2898</td>\n",
       "      <td>12867</td>\n",
       "      <td>3</td>\n",
       "      <td>...</td>\n",
       "      <td>960</td>\n",
       "      <td>640</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>25</td>\n",
       "      <td>-1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40023</th>\n",
       "      <td>6324759195855019847</td>\n",
       "      <td>2190715765</td>\n",
       "      <td>165</td>\n",
       "      <td>16</td>\n",
       "      <td>2100235,gd_2100001,2100126,3001793,3001949,300...</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1619</td>\n",
       "      <td>408</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>960</td>\n",
       "      <td>640</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>30</td>\n",
       "      <td>-1.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1041674 rows × 35 columns</p>\n",
       "</div>"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 14
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-17T05:46:10.230182Z",
     "start_time": "2025-06-17T05:46:10.222297Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import datetime\n",
    "import time\n",
    "import gc"
   ],
   "id": "93d3a6b01b167018",
   "outputs": [],
   "execution_count": 15
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-17T06:16:18.716359Z",
     "start_time": "2025-06-17T06:16:02.732135Z"
    }
   },
   "cell_type": "code",
   "source": [
    "data['day'] = data['time'].apply(lambda x : int(time.strftime(\"%d\", time.localtime(x))))\n",
    "data['hour'] = data['time'].apply(lambda x : int(time.strftime(\"%H\", time.localtime(x))))"
   ],
   "id": "70be36bfb219794f",
   "outputs": [],
   "execution_count": 16
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-17T06:31:15.959175Z",
     "start_time": "2025-06-17T06:31:15.656389Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 历史点击率\n",
    "# 时间转换\n",
    "data['period'] = data['day']\n",
    "data['period'][data['period']<27] = data['period'][data['period']<27] + 31"
   ],
   "id": "16b9fc78be9718c",
   "outputs": [],
   "execution_count": 17
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-17T06:49:25.583321Z",
     "start_time": "2025-06-17T06:49:14.333428Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 历史点击率\n",
    "# 时间转换 - 修复链式赋值警告\n",
    "data['period'] = data['day']\n",
    "data.loc[data['period'] < 27, 'period'] = data.loc[data['period'] < 27, 'period'] + 31\n",
    "\n",
    "for feat in ['advert_id', 'advert_industry_inner', 'advert_name', 'campaign_id', 'creative_height',\n",
    "             'creative_tp_dnf', 'creative_width', 'province', 'f_channel']:\n",
    "    \n",
    "    gc.collect()\n",
    "    res_list = []  # 使用列表收集每个周期的结果\n",
    "    \n",
    "    temp = data[[feat, 'period', 'click']].copy()\n",
    "    \n",
    "    for period in range(27, 35):\n",
    "        # 创建过滤条件（防止数据泄漏）\n",
    "        if period == 27:\n",
    "            cond = (temp['period'] <= period)\n",
    "        else:\n",
    "            cond = (temp['period'] < period)\n",
    "        \n",
    "        # 分组计算\n",
    "        group = temp[cond].groupby(feat)\n",
    "        \n",
    "        # 创建结果DataFrame\n",
    "        count = pd.DataFrame({\n",
    "            feat: group.groups.keys(),  # 保留特征值\n",
    "            f'{feat}_all': group.size(),  # 总计数\n",
    "            f'{feat}_1': group['click'].sum()  # 点击计数\n",
    "        }).reset_index(drop=True)\n",
    "        \n",
    "        # 计算点击率\n",
    "        count[f'{feat}_rate'] = round(count[f'{feat}_1'] / count[f'{feat}_all'], 5)\n",
    "        count['period'] = period\n",
    "        \n",
    "        # 只保留必要列\n",
    "        count = count[[feat, 'period', f'{feat}_rate']]\n",
    "        count.fillna(0, inplace=True)\n",
    "        \n",
    "        # 添加到结果列表\n",
    "        res_list.append(count)\n",
    "    \n",
    "    # 合并所有周期的结果\n",
    "    res = pd.concat(res_list, ignore_index=True)\n",
    "    \n",
    "    print(f'{feat} processed')\n",
    "    \n",
    "    # 合并回主数据集\n",
    "    data = data.merge(res, on=[feat, 'period'], how='left')"
   ],
   "id": "32fd659f23c5810c",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "advert_id processed\n",
      "advert_industry_inner processed\n",
      "advert_name processed\n",
      "campaign_id processed\n",
      "creative_height processed\n",
      "creative_tp_dnf processed\n",
      "creative_width processed\n",
      "province processed\n",
      "f_channel processed\n"
     ]
    }
   ],
   "execution_count": 21
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-17T07:59:29.113407Z",
     "start_time": "2025-06-17T07:56:30.593594Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import gc\n",
    "import datetime\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "from sklearn.model_selection import StratifiedKFold\n",
    "import lightgbm as lgb\n",
    "\n",
    "# 假设 'data' 是包含所有数据的 DataFrame\n",
    "# 删除没用的特征\n",
    "drop = ['click', 'time', 'instance_id', 'user_tags', \n",
    "        'app_paid', 'creative_is_js', 'creative_is_voicead']\n",
    "\n",
    "# 确定训练集大小 - 这里假设 train_fail 是训练集\n",
    "train_size = train_fail.shape[0]  # 替换为你的实际训练集大小\n",
    "train = data.iloc[:train_size]\n",
    "test = data.iloc[train_size:]\n",
    "\n",
    "y_train = train.loc[:, 'click'].values\n",
    "res = test.loc[:, ['instance_id']].copy()  # 保留测试集的ID\n",
    "\n",
    "train.drop(drop, axis=1, inplace=True)\n",
    "print('train:', train.shape)\n",
    "test.drop(drop, axis=1, inplace=True)\n",
    "print('test:', test.shape)\n",
    "\n",
    "# 准备特征数据\n",
    "feature_names = train.columns.tolist()\n",
    "X_loc_train = train.values\n",
    "X_loc_test = test.values\n",
    "\n",
    "# 五折交叉训练\n",
    "skf = StratifiedKFold(n_splits=5, shuffle=True, random_state=1024)\n",
    "\n",
    "# LightGBM 参数\n",
    "params = {\n",
    "    'boosting_type': 'gbdt',\n",
    "    'objective': 'binary',\n",
    "    'metric': 'binary_logloss',\n",
    "    'num_leaves': 48,\n",
    "    'max_depth': -1,\n",
    "    'learning_rate': 0.05,\n",
    "    'n_estimators': 2000,\n",
    "    'max_bin': 425,\n",
    "    'subsample_for_bin': 50000,\n",
    "    'min_split_gain': 0,\n",
    "    'min_child_weight': 5,\n",
    "    'min_child_samples': 10,\n",
    "    'subsample': 0.8,\n",
    "    'subsample_freq': 1,\n",
    "    'colsample_bytree': 1,\n",
    "    'reg_alpha': 3,\n",
    "    'reg_lambda': 5,\n",
    "    'random_state': 1000,\n",
    "    'n_jobs': 10,\n",
    "    'verbosity': -1  # 等同于 silent=True\n",
    "}\n",
    "\n",
    "baseloss = []\n",
    "loss = 0\n",
    "\n",
    "# 存储每个fold的预测结果\n",
    "fold_predictions = []\n",
    "\n",
    "for i, (train_index, test_index) in enumerate(skf.split(X_loc_train, y_train)):\n",
    "    print(f\"\\n========== Fold {i+1}/5 ==========\")\n",
    "    \n",
    "    # 创建训练集和验证集\n",
    "    X_train, X_val = X_loc_train[train_index], X_loc_train[test_index]\n",
    "    y_train_fold, y_val = y_train[train_index], y_train[test_index]\n",
    "    \n",
    "    # 创建LightGBM数据集\n",
    "    lgb_train = lgb.Dataset(X_train, y_train_fold)\n",
    "    lgb_val = lgb.Dataset(X_val, y_val, reference=lgb_train)\n",
    "    \n",
    "    # 训练模型\n",
    "    model = lgb.train(\n",
    "        params,\n",
    "        lgb_train,\n",
    "        num_boost_round=2000,  # 最大迭代次数\n",
    "        valid_sets=[lgb_val],\n",
    "        valid_names=['valid'],\n",
    "        callbacks=[\n",
    "            lgb.early_stopping(stopping_rounds=100, verbose=True),\n",
    "            lgb.log_evaluation(period=100)  # 每100轮输出一次\n",
    "        ]\n",
    "    )\n",
    "    \n",
    "    # 获取最佳分数\n",
    "    best_score = model.best_score['valid']['binary_logloss']\n",
    "    baseloss.append(best_score)\n",
    "    loss += best_score\n",
    "    print(f\"Fold {i} best logloss: {best_score:.6f}\")\n",
    "    \n",
    "    # 在测试集上进行预测\n",
    "    test_pred = model.predict(X_loc_test, num_iteration=model.best_iteration)\n",
    "    fold_predictions.append(test_pred)\n",
    "    \n",
    "    # 保存当前fold的预测结果到res\n",
    "    res[f'prob_{i}'] = test_pred\n",
    "    print(f\"Test prediction mean (Fold {i}): {test_pred.mean():.6f}\")\n",
    "    \n",
    " \n",
    "\n",
    "# 计算平均logloss\n",
    "avg_loss = loss / 5\n",
    "print(\"\\nCross-validation results:\")\n",
    "print(f\"Individual fold logloss: {baseloss}\")\n",
    "print(f\"Average logloss: {avg_loss:.6f}\")\n",
    "\n",
    "# 计算加权平均预测\n",
    "final_prediction = np.mean(fold_predictions, axis=0)\n",
    "res['predicted_score'] = final_prediction\n",
    "\n",
    "# 提交结果\n",
    "mean_pred = res['predicted_score'].mean()\n",
    "print(f\"\\nFinal prediction mean: {mean_pred:.6f}\")\n",
    "\n",
    "now = datetime.datetime.now().strftime('%m-%d-%H-%M')\n",
    "output_path = f\"lgb_native_{now}.csv\"\n",
    "res[['instance_id', 'predicted_score']].to_csv(output_path, index=False)\n",
    "print(f\"Predictions saved to: {output_path}\")\n",
    "\n",
    "# 特征重要性分析\n",
    "print(\"\\nFeature importance analysis:\")\n",
    "feature_imp = pd.DataFrame({\n",
    "    'Feature': feature_names,\n",
    "    'Importance': model.feature_importance(importance_type='gain')\n",
    "})\n",
    "feature_imp = feature_imp.sort_values('Importance', ascending=False).reset_index(drop=True)\n",
    "\n",
    "# 打印前20个重要特征\n",
    "print(feature_imp.head(20))\n",
    "\n",
    "# 保存特征重要性\n",
    "feature_imp.to_csv(f\"feature_importance_{now}.csv\", index=False)\n",
    "print(f\"Feature importance saved to: feature_importance_{now}.csv\")"
   ],
   "id": "cc2fe7d7727b7993",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "train: (1001650, 40)\n",
      "test: (40024, 40)\n",
      "\n",
      "========== Fold 1/5 ==========\n",
      "Training until validation scores don't improve for 100 rounds\n",
      "[100]\tvalid's binary_logloss: 0.416963\n",
      "[200]\tvalid's binary_logloss: 0.415931\n",
      "[300]\tvalid's binary_logloss: 0.415588\n",
      "[400]\tvalid's binary_logloss: 0.415427\n",
      "[500]\tvalid's binary_logloss: 0.415297\n",
      "[600]\tvalid's binary_logloss: 0.415248\n",
      "[700]\tvalid's binary_logloss: 0.415203\n",
      "[800]\tvalid's binary_logloss: 0.415212\n",
      "Early stopping, best iteration is:\n",
      "[713]\tvalid's binary_logloss: 0.415192\n",
      "Fold 0 best logloss: 0.415192\n",
      "Test prediction mean (Fold 0): 0.209348\n",
      "\n",
      "========== Fold 2/5 ==========\n",
      "Training until validation scores don't improve for 100 rounds\n",
      "[100]\tvalid's binary_logloss: 0.419242\n",
      "[200]\tvalid's binary_logloss: 0.41826\n",
      "[300]\tvalid's binary_logloss: 0.417975\n",
      "[400]\tvalid's binary_logloss: 0.41787\n",
      "[500]\tvalid's binary_logloss: 0.417828\n",
      "[600]\tvalid's binary_logloss: 0.417818\n",
      "[700]\tvalid's binary_logloss: 0.417806\n",
      "Early stopping, best iteration is:\n",
      "[629]\tvalid's binary_logloss: 0.417793\n",
      "Fold 1 best logloss: 0.417793\n",
      "Test prediction mean (Fold 1): 0.210203\n",
      "\n",
      "========== Fold 3/5 ==========\n",
      "Training until validation scores don't improve for 100 rounds\n",
      "[100]\tvalid's binary_logloss: 0.418095\n",
      "[200]\tvalid's binary_logloss: 0.417185\n",
      "[300]\tvalid's binary_logloss: 0.416863\n",
      "[400]\tvalid's binary_logloss: 0.416741\n",
      "[500]\tvalid's binary_logloss: 0.416643\n",
      "[600]\tvalid's binary_logloss: 0.416618\n",
      "Early stopping, best iteration is:\n",
      "[523]\tvalid's binary_logloss: 0.416609\n",
      "Fold 2 best logloss: 0.416609\n",
      "Test prediction mean (Fold 2): 0.209465\n",
      "\n",
      "========== Fold 4/5 ==========\n",
      "Training until validation scores don't improve for 100 rounds\n",
      "[100]\tvalid's binary_logloss: 0.418272\n",
      "[200]\tvalid's binary_logloss: 0.417314\n",
      "[300]\tvalid's binary_logloss: 0.416982\n",
      "[400]\tvalid's binary_logloss: 0.416849\n",
      "[500]\tvalid's binary_logloss: 0.416787\n",
      "[600]\tvalid's binary_logloss: 0.416781\n",
      "Early stopping, best iteration is:\n",
      "[548]\tvalid's binary_logloss: 0.416755\n",
      "Fold 3 best logloss: 0.416755\n",
      "Test prediction mean (Fold 3): 0.208565\n",
      "\n",
      "========== Fold 5/5 ==========\n",
      "Training until validation scores don't improve for 100 rounds\n",
      "[100]\tvalid's binary_logloss: 0.417853\n",
      "[200]\tvalid's binary_logloss: 0.41683\n",
      "[300]\tvalid's binary_logloss: 0.416499\n",
      "[400]\tvalid's binary_logloss: 0.416359\n",
      "[500]\tvalid's binary_logloss: 0.416297\n",
      "[600]\tvalid's binary_logloss: 0.4163\n",
      "Early stopping, best iteration is:\n",
      "[528]\tvalid's binary_logloss: 0.416285\n",
      "Fold 4 best logloss: 0.416285\n",
      "Test prediction mean (Fold 4): 0.210299\n",
      "\n",
      "Cross-validation results:\n",
      "Individual fold logloss: [0.4151918005376422, 0.41779349997945153, 0.416608539525935, 0.4167554618596391, 0.41628455550948634]\n",
      "Average logloss: 0.416527\n",
      "\n",
      "Final prediction mean: 0.209576\n",
      "Predictions saved to: lgb_native_06-17-15-59.csv\n",
      "\n",
      "Feature importance analysis:\n",
      "                       Feature     Importance\n",
      "0         creative_tp_dnf_rate  718545.273839\n",
      "1                       app_id   76071.987001\n",
      "2             advert_name_rate   47965.978271\n",
      "3                        model   45571.645606\n",
      "4                inner_slot_id   45465.194800\n",
      "5                          osv   32680.078992\n",
      "6               advert_id_rate   31175.829193\n",
      "7                         adid   24140.055347\n",
      "8                  app_cate_id   20695.120854\n",
      "9                  creative_id   20422.295760\n",
      "10                        make   15385.918010\n",
      "11            campaign_id_rate   14751.220445\n",
      "12                        city   14544.521776\n",
      "13                     orderid   14520.207525\n",
      "14               province_rate   11093.245167\n",
      "15                        hour    9677.529231\n",
      "16                 campaign_id    9203.526986\n",
      "17  advert_industry_inner_rate    4380.603572\n",
      "18                         nnt    3897.697349\n",
      "19              f_channel_rate    3797.782259\n",
      "Feature importance saved to: feature_importance_06-17-15-59.csv\n"
     ]
    }
   ],
   "execution_count": 29
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "f4d8bc8a586fc348"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "5bd948c8321eff66"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "bc59854c555fa9ce"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "d0fe0f5a209ad819"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "2cd05ccb996fa84a"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "dbc7e7ed3bd19e96"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "e730f07d77b30857"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
